<?php

Raise::load('core.RaiseShape');
Raise::load('core.RaisePoint');
Raise::load('core.RaiseVariable');
Raise::load('core.RaiseInvalidArgumentException');

/**
 * RaiseCircle class
 * represents a circle based on the radius
 *
 * @author Sam-Mauris Yong <hellclanner at live dot com>
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.Core.Geometry
 * @since 1.2
 */
class RaiseCircle extends RaiseShape {

    /**
     * The radius of the circle
     * @var integer|double
     */
    private $radius;

    /**
     * The location of the center of the circle
     * @var RaisePoint
     */
    private $location;

    /**
     * Create a RaiseCircle with a radius
     * @param integer|double $r The radius of the circle
     */
    public function __construct($r) {
        $this->location(RaisePoint::zero());
        $this->radius($r);
    }

    /**
     * Get or set the radius of the circle
     * @param integer|double $r (optional) The new radius of the circle
     * @return integer|double
     */
    public function radius($r = null){
        if(func_num_args() == 1){
            $this->radius = $r;
        }
        return $this->radius;
    }

    /**
     * Get the diameter of the circle
     * @return integer|double
     */
    public function diameter(){
        return $this->radius * 2;
    }

    /**
     * Get the circumference of the circle
     * @return integer|double
     */
    public function circumference(){
        return pi() * $this->diameter();
    }

    /**
     * Get the area of the circle
     * @return integer|double
     */
    public function area(){
        return pi() * pow($this->radius, 2);
    }

    /**
     * Get or set the location of the center point of the circle
     * @param RaisePoint $l (Optional) When specified, the center of the circle will be set to this value
     * @return RaisePoint The current location of the center point of the circle
     */
    public function location($l = false){
        if($l !== false){
            if(RaiseVariable::isNotA($l,'RaisePoint')){
                throw new RaiseInvalidArgumentException("Location has to be a RaisePoint instance");
            }
            $this->location = $l;
        }
        return $this->location;
    }

}
